package flower.home.common.poi.bo;

import cn.abellflower.utils.EwmUtil;
import flower.home.common.poi.DataTempEnum;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author gbzdyf@126.com
 * @Date 2021/6/17 上午10:12
 */
@Data
public class ExcelDataBo {


    public static List<ExcelDataBo> transExcelDataBoList(List<String[]> subList) {
        List<ExcelDataBo> excelDataBos = new ArrayList<>(subList.size());
        for (String[] excelDatumArr : subList) {
            ExcelDataBo excelDataBo = new ExcelDataBo();
            try {
                transT(excelDataBo, excelDatumArr);
            } catch (Exception e) {
                System.out.println(String.format("报错[{}]", excelDatumArr));
            }
            excelDataBos.add(excelDataBo);
        }
        System.out.println(excelDataBos.size());


        return excelDataBos;
    }

    public static <T> void transT(T t, String[] excelDatumArr) throws Exception {
        Class<?> aClass = t.getClass();
        for (int i = 0; i < excelDatumArr.length; i++) {
            Field field = aClass.getDeclaredField(DataTempEnum.getAllColumnMap().get(i).getColumnAttribute());
            field.setAccessible(true);
            if (StringUtils.isBlank(excelDatumArr[i]) && StringUtils.isNotBlank(DataTempEnum.getAllColumnMap().get(i).getExcelDefaultValue())) {
                field.set(t, DataTempEnum.getAllColumnMap().get(i).getExcelDefaultValue());
            } else {
                field.set(t, excelDatumArr[i]);
            }
        }
    }

    private String orderNo;
    private String createdTime;
    private String expireTIme;
    private String taxAmount;
    private String status;
    private String buyerName;
    private String invoiceCodeAndNum;
    private String ewmUrl;
    private String goodsName;
    private String unit;
    private String taxPrice;
    private String num;
    private String amount;
    private String taxRate;
    private String deductAmount;
    private String discountAmount;
}
